package customerEnter.Frame.filter;

import java.util.Map;

import javax.servlet.ServletContextEvent;

import customerEnter.Frame.DaoDataTransmission.ImageURLTransmission;
import customerEnter.Frame.DaoDataTransmission.WebAppsInfo;
import customerEnter.Frame.Enum.ImageUrlEnum;
import customerEnter.Frame.Utils.Log4j;
import customerEnter.Frame.bean.FrameBeansModels;
import customerEnter.Frame.oss.OSSUseTransmission;
import customerEnter.Frame.oss.OSSxml;
import customerEnter.Frame.scanning.ScanningAnalysis;
import customerEnter.Frame.scanning.ScanningExtendedConfig;
import customerEnter.Frame.scanning.scanningServer.ConfigPackageServer;
import customerEnter.Frame.scanning.scanningServer.ProjectScanningModelServer;
import customerEnter.tool.WhetherToEmpty;

/**
 * 初始化程序
 * 
 * 类名称：InitializationDataFilter 类描述： 创建人：dy 创建时间：2017-4-5 下午7:40:47
 * 
 */
public class InitializationDataFilter {
	/**
	 * 初始化oss服務
	 */
	public static void InitializationOSS() {
		try {
			OSSxml.InOss();
			Log4j.Log4jOutInfo(OSSUseTransmission.getAccessKeyId());
			Log4j.Log4jOutInfo(OSSUseTransmission.getAccessKeySecret());
			Log4j.Log4jOutInfo(OSSUseTransmission.getAccessURL());
			Log4j.Log4jOutInfo(OSSUseTransmission.getAucketName());
			Log4j.Log4jOutInfo(OSSUseTransmission.getEndpoint());
			Log4j.Log4jOutInfo("載入oss成功");
		} catch (Exception e) {
			Log4j.Log4jOutInfo("載入oss失敗");
		}
	}

	/**
	 * 初始化圖片路徑
	 */
	public static void InitializationImageUrlEnum() {
		Log4j.Log4jOutInfo("----------------------------程序程序啟動中-----------------------------");
		Log4j.Log4jOutInfo("----------------------------日誌啟動中-----------------------------");
		ImageURLTransmission.SET_IMAGEURL(ImageUrlEnum.LOCALHOST.getIMAGEURLVALUE());
		if (WhetherToEmpty.StringWhetherToEmpty(ImageURLTransmission.GET_IMAGEURL())) {
			Log4j.Log4jOutInfo("-----------------圖片路徑沒有載入------------------");
		} else {
			Log4j.Log4jOutInfo("-----------------圖片路徑已經載入------------------");
		}
	}

	/**
	 * 读取项目信息
	 */
	public static void InitializationWebAppsInfo(ServletContextEvent ContextEvent) {
		WebAppsInfo.requestWebName(ContextEvent);
		Log4j.Log4jOutInfo("--------------------------讀取系統信息--------------------------");
		Log4j.Log4jOutInfo(WebAppsInfo.System);
		Log4j.Log4jOutInfo(WebAppsInfo.webContainer);

		Log4j.Log4jOutInfo(WebAppsInfo.webDataBase);
		Log4j.Log4jOutInfo(WebAppsInfo.webEdition);
		Log4j.Log4jOutInfo(WebAppsInfo.webJavaEdition);
		Log4j.Log4jOutInfo(WebAppsInfo.webName);
		Log4j.Log4jOutInfo(WebAppsInfo.webTechnology);
		Log4j.Log4jOutInfo(WebAppsInfo.webUrl);
		Log4j.Log4jOutInfo("--------------------------系統使用率---------------------------");
		for (String str : WebAppsInfo.getDisk()) {
			Log4j.Log4jOutInfo(str);
		}
	}

	/**
	 * 框架初始化（掃描）
	 */
	public static void InitializationScanning() {
		Log4j.Log4jOutInfo("------------------------開始掃描包：------------");
		ScanningExtendedConfig scanningExtendedConfig = new ProjectScanningModelServer();
		ScanningAnalysis scanningAnalysis = new ConfigPackageServer();
		try {
			Map<String, Class<?>> map = scanningExtendedConfig.scanningPackage(scanningAnalysis);
			Log4j.Log4jOutInfo("掃描的類：" + map.size() + "");
			// Map<String, Field[]> fMap =
			// scanningExtendedConfig.scanningClass(map);

			Map<String, FrameBeansModels> fMap = scanningExtendedConfig.scanningClassModels(map);
			Log4j.Log4jOutInfo("反射到的屬性 的類：" + fMap.size() + "");
		} catch (Exception e1) {
			Log4j.Log4jOutInfo(e1.getMessage());
		}

		Log4j.Log4jOutInfo("------------------------ 掃描包結束------------");
	}

}
